#ifndef __MP_NET_BASE_H__
#define __MP_NET_BASE_H__

#include "eventloop.h"
#include "net_context.h"

#include "logger.h"

#include <string>

#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>

#include <map>

class NetBase {
public:
    NetBase();
    virtual ~NetBase();

    virtual int init(std::string host, int port) = 0;
    
    NetContext* get_net_context(std::string session_id);

private:
    virtual void __recv_cb(ev::io &w, int revents) = 0;
    virtual void __send_cb(ev::io &w, int revents) = 0;

protected:
    //NetContext
    void add_net_context(NetContext* context);
    void del_net_context(NetContext* context);

protected:
    Logger *m_logger = Logger::get_instance();

    ev::dynamic_loop *m_loop;

    std::map<std::string, NetContext *> m_context_map;
};

#endif
